clear
set more off

/* Load data */

import delimited "zhang2023.csv", varnames(1) encoding(ISO-8859-1)clear

/* Generate Biden and Trump supporter indicators and their respective interactions with treatment status */
gen trump_supporter = (vote_intent == 1 | vote_intent == 2)
gen biden_supporter = (vote_intent == 5 | vote_intent == 6)
gen trump_supporter_treated = trump_supporter * treatment
gen biden_supporter_treated = biden_supporter * treatment

/* Exclude participants who did not complete the survey (including those who failed attention checks) by dropping those who did not answer the last item */
drop if race == .
* Un-comment the line below to obtain estimates reported in Supplementary Table 4 *
* drop if _n >  4000 *

/* Exclude participants who indicated they supported neither Biden nor Trump (prior to treatment) */
drop if vote_intent == 7

/* Recode climate_consensus as binary */
replace climate_consensus= (climate_consensus == 6)

/* Recode the orders response options for ease of interpretation */
foreach i of varlist nature_informed nature_unbiased scientists_informed scientists_unbiased climate_belief {
	replace `i' = 6 - `i'
}
replace biden_vs_trump = 8 - biden_vs_trump

/* Label variables and values */


/* Standardize outcome variables */
foreach i of varlist nature_informed nature_unbiased biden_20 trump_21 biden_vs_trump selected_nature scientists_informed scientists_unbiased climate_consensus climate_belief {
	egen mean_`i' = mean(`i')
	egen sd_`i' = sd(`i')
	replace `i' = ( `i' - mean_`i' ) / (sd_`i')
	drop mean_`i'
	drop sd_`i'
}

/* Generate estimates presented in Table 2 */

/** Row2 1-2 **/
eststo: reg nature_informed trump_supporter_treated biden_supporter_treated trump_supporter, robust
eststo: reg nature_unbiased trump_supporter_treated biden_supporter_treated trump_supporter, robust

/** Rows 3-5 **/
eststo: reg biden_20 trump_supporter_treated biden_supporter_treated trump_supporter, robust
eststo: reg trump_21 trump_supporter_treated biden_supporter_treated trump_supporter, robust
eststo: reg biden_vs_trump trump_supporter_treated biden_supporter_treated trump_supporter, robust

/** Row 6 **/
eststo: reg selected_nature trump_supporter_treated biden_supporter_treated trump_supporter, robust

/** Rows 7-8 **/
eststo: reg scientists_informed trump_supporter_treated biden_supporter_treated trump_supporter, robust
eststo: reg scientists_unbiased trump_supporter_treated biden_supporter_treated trump_supporter, robust

/** Row 9-10 **/
eststo: reg climate_consensus trump_supporter_treated biden_supporter_treated trump_supporter, robust
eststo: reg climate_belief trump_supporter_treated biden_supporter_treated trump_supporter, robust

/** Export table **/
esttab using t2.tex, se label title(Table 2 Estimates) nonumbers mtitles("Nature informed" "Nature unbiased" "Biden 2020" "Trump 2021" "Biden vs Trump" "Nature is selected" "Climate Consensus" "Climate Belief" "Scientists informed" "Scientists unbiased") noconstant replace
eststo clear

/* Bayes factors for interpreted null results*/
/** Bayesian univariate linear regression **/
set seed 1
bayesmh biden_20 trump_supporter_treated biden_supporter_treated trump_supporter, likel(normal({var})) prior({biden_20: _cons trump_supporter_treated biden_supporter_treated trump_supporter}, normal(0,1)) prior({var}, jeffreys) saving(full1, replace)
estimates store full1
bayesmh trump_21 trump_supporter_treated biden_supporter_treated trump_supporter, likel(normal({var})) prior({trump_21: _cons trump_supporter_treated biden_supporter_treated trump_supporter}, normal(0,1)) prior({var}, jeffreys) saving(full2, replace)
estimates store full2
bayesmh biden_vs_trump trump_supporter_treated biden_supporter_treated trump_supporter, likel(normal({var})) prior({biden_vs_trump: _cons trump_supporter_treated biden_supporter_treated trump_supporter}, normal(0,1)) prior({var}, jeffreys) saving(full3, replace)
estimates store full3
bayesmh biden_20 trump_supporter, likel(normal({var})) prior({biden_20: _cons trump_supporter}, normal(0,1)) prior({var}, jeffreys) saving(restricted1, replace)
estimates store restricted1
bayesmh trump_21 trump_supporter, likel(normal({var})) prior({trump_21: _cons trump_supporter}, normal(0,1)) prior({var}, jeffreys) saving(restricted2, replace)
estimates store restricted2
bayesmh biden_vs_trump trump_supporter, likel(normal({var})) prior({biden_vs_trump: _cons trump_supporter}, normal(0,1)) prior({var}, jeffreys) saving(restricted3, replace)
estimates store restricted3
bayesstats ic full1 restricted1, bayesfactor
bayesstats ic full2 restricted2, bayesfactor
bayesstats ic full3 restricted3, bayesfactor

/** Bayesian multivariate linear regression **/
bayesmh biden_20 trump_21 biden_vs_trump = trump_supporter_treated biden_supporter_treated trump_supporter, likel(mvnormal({sigma, m})) prior({biden_20: _cons trump_supporter_treated biden_supporter_treated trump_supporter}, normal(0,1)) prior({trump_21: _cons trump_supporter_treated biden_supporter_treated trump_supporter}, normal(0,1)) prior({biden_vs_trump: _cons trump_supporter_treated biden_supporter_treated trump_supporter}, normal(0,1)) prior({sigma, m}, mvnorm(3,0,1)) saving(full, replace)
estimates store full
bayesmh biden_20 trump_21 biden_vs_trump = trump_supporter, likel(mvnormal({sigma, m})) prior({biden_20:  _cons trump_supporter}, normal(0,1)) prior({trump_21: _cons trump_supporter}, normal(0,1)) prior({biden_vs_trump: _cons trump_supporter}, normal(0,1)) prior({sigma, m}, mvnorm(3,0,1)) saving(restricted, replace)
estimates store restricted
bayesstats ic full restricted
